import commonJs from './common'
import store from '../../store'
const payCommon = {
	xcxPay(result,urlPage=''){
		if(urlPage == ''){
			urlPage = '/pages/order/index'
		}
		uni.requestPayment({
			appId:result.appId,
		    timeStamp: result.timeStamp,
		    nonceStr: result.nonceStr,
		    package: result.package,
		    signType: result.signType,
		    paySign: result.paySign,
		    success: function (res) {
				store.dispatch('clearnCart')
				if (res.errMsg == "requestPayment:ok") { // 调用支付成功
					commonJs.waitFunction.waitRedirectTo('支付成功',urlPage)
				}else{
					commonJs.waitFunction.waitRedirectTo('支付失败',res.errMsg)
				}
		    },
		    fail: function (err) {
				commonJs.waitFunction.waitRedirectTo('支付已取消',urlPage)
				store.dispatch('clearnCart')
		    }
		});
	}
}
export default payCommon